import java.awt.Point;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


public class Author 
{
	public Map<Integer,Integer> co_authors_Map = new HashMap<Integer,Integer>();
	public Map<Integer,Double> co_authors_Dist = new HashMap<Integer,Double>();
	public int authorID;
	public Point location;
	public Author(int authorID)
	{
		this.authorID = authorID;
		
		
	}
	//==============================================================
	public Author(int authorID,Point location)
	{
		this.authorID = authorID;
		this.location = location;
	}
	//=============================================================
	public void addCoAuthor(int co_author_ID)
	{
		if(checkExist(co_author_ID))
		{
			int weight = co_authors_Map.get(co_author_ID).intValue();
			weight++;
			co_authors_Map.put(co_author_ID, weight);
		}
		else
		{
			co_authors_Map.put(co_author_ID, 1);
		}
	}
	//=============================================================
	public void addCoAuthor(int co_author_ID,Point co_location)
	{
		if(checkExist(co_author_ID))
		{
			int weight = co_authors_Map.get(co_author_ID).intValue();
			weight++;
			co_authors_Map.put(co_author_ID, weight);
			double dist = CalculateDistance(co_author_ID,co_location);
			//co_authors_Dist.put(co_author_ID, dist);
		}
		else
		{
			co_authors_Map.put(co_author_ID, 1);
		}
	}
	//==============================================================
	public void addCoAuthor(int co_author_ID,int weight)
	{
		co_authors_Map.put(co_author_ID, weight);
	}
	//===============================================================
	public void addCoAuthor(int co_author_ID,int weight,Point co_location)
	{
		co_authors_Map.put(co_author_ID, weight);
		double dist = CalculateDistance(co_author_ID,co_location);
		//co_authors_Dist.put(co_author_ID, dist);
	}
	//===============================================================
	private boolean checkExist(int co_author_ID)
	{
		return co_authors_Map.containsKey(co_author_ID);
	}
	//==============================================================
	public int getWeight(int co_author_ID)
	{
		if(checkExist(co_author_ID))
			return co_authors_Map.get(co_author_ID).intValue();
		else 
			return -1;
	}
	//=============================================================
	public String getStringOfCo_Authors()
	{
		String str = Integer.toString(authorID)+","+ "0";
		for (Map.Entry<Integer, Integer> entry : co_authors_Map.entrySet()) 
		{
			Integer key = entry.getKey();
			Integer value = entry.getValue();
		    str = str +"-" +key + "," + value;
		}
		return str;
	}
	//============================================================
	public Integer[] getCoauthorsID()
	{
		Integer ia[] = new Integer[co_authors_Map.keySet().size()];
		return  co_authors_Map.keySet().toArray(ia);
	}
	//============================================================
	public double CalculateDistance(int co_author_ID, Point co_location)
	{
		double dist = 0.0;
		dist = Math.sqrt(Math.pow((co_location.x - this.location.x),2) + Math.pow((co_location.y-this.location.y),2));
		//co_authors_Dist.put(co_author_ID, dist);
		return dist;
	}
	//============================================================
	public double getDistanceTo(int co_author_ID)
	{
		if(checkExist(co_author_ID))
			return co_authors_Dist.get(co_author_ID);
		else
			return -1;
	}
}
